﻿<html>
<head>
    <title>显示列设置</title>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/config.js"></script>
    <script src="../../Comm/Gener.js?va2=2" type="text/javascript"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="Stylesheet" />
    <script type="text/javascript">

        //页面启动函数.
        $(function () {

            var frmID = GetQueryString("FrmID");

            var mapAttrs = new Entities("BP.Sys.MapAttrs");
            mapAttrs.Retrieve("FK_MapData", frmID, "Idx");

            //先输出 BillNo,Title 
            var topFields = ",BillNo,Title,";
            for (var i = 0; i < mapAttrs.length; i++) {

                var mapAttr = mapAttrs[i];
                if (topFields.indexOf(mapAttr.KeyOfEn + ",") == -1)
                   continue;

                var mapAttrEn = new Entity("BP.Sys.MapAttr", mapAttr);
                var html = "";
                html += "<tr>";
                html += "<td>#</td>";
                html += "<td>" + mapAttr.KeyOfEn + "</td>";

                html += "<td> <input value='" + mapAttr.Name + "' type=text style='width:100%;'  id='TB_" + mapAttr.KeyOfEn + "' /></td>";
                html += "<td> <input value='" + mapAttr.UIWidth + "' type=text style='width:40px;'  id='TBW_" + mapAttr.KeyOfEn + "' /></td>";

                //if (mapAttrEn.GetPara("SearchVisable") != "1")
                //    mapAttrEn.Update();

                html += "<td>普通</td>";

                if (mapAttrEn.GetPara("SearchVisable") == "1")
                    html += "<td><a  href=\"javascript:HiddenIt('" + mapAttr.MyPK + "')\">隐藏</a></td>";
                else if (mapAttrEn.GetPara("SearchVisable") == "0") {
                    html += "<td style='text-align:right' ><a href=\"javascript:ShowIt('" + mapAttr.MyPK + "')\">显示</a></td>";
                } else {
                    if (mapAttr.UIVisible == 1) {
                        html += "<td><a  href=\"javascript:HiddenIt('" + mapAttr.MyPK + "')\">隐藏</a></td>";
                    } else {
                        html += "<td style='text-align:right' ><a href=\"javascript:ShowIt('" + mapAttr.MyPK + "')\">显示</a></td>";
                    }
                }
                html += "<td></td>";

                html += "</tr>";

                $("#Table1 tr:last").after(html);
            }

            //不显示的字段.
            var cutAttrs = "OID,AtPara,RDT,Title,BillNo,Starter,StarterName,BillState,";
            var idx = 0;
            for (var i = 0; i < mapAttrs.length; i++) {

                var mapAttr = mapAttrs[i];

                if (mapAttr.IsRefAttr == 1)
                    continue; // 如果是外键的扩展字段也要排除. Dict_BanJi 显示， Dict_BanJiT就不要显示了.

                if (cutAttrs.indexOf(mapAttr.KeyOfEn + ",") != -1)
                    continue; //排除不让其显示的字段.


                idx++;

                var mapAttrEn = new Entity("BP.Sys.MapAttr", mapAttr);
                var html = "";

                html += "<tr>";
                html += "<td>" + idx + "</td>";
                html += "<td>" + mapAttr.KeyOfEn + "</td>";

                html += "<td> <input value='" + mapAttr.Name + "' type=text style='width:100%;'  id='TB_" + mapAttr.KeyOfEn + "' /></td>";
                html += "<td> <input value='" + mapAttr.UIWidth + "' type=text style='width:40px;'  id='TBW_" + mapAttr.KeyOfEn + "' /></td>";

                if (mapAttrEn.LGType == 0)
                    html += "<td>普通</td>";
                if (mapAttrEn.LGType == 1)
                    html += "<td>枚举</td>";
                if (mapAttrEn.LGType == 2)
                    html += "<td>外键</td>";

                if (mapAttrEn.GetPara("SearchVisable") == "1")
                    html += "<td><a  href=\"javascript:HiddenIt('" + mapAttr.MyPK + "')\">隐藏</a></td>";
               else if (mapAttrEn.GetPara("SearchVisable") == "0") {
                    html += "<td style='text-align:right' ><a href=\"javascript:ShowIt('" + mapAttr.MyPK + "')\">显示</a></td>";
                } else {
                    if (mapAttr.UIVisible == 1) {
                        html += "<td><a  href=\"javascript:HiddenIt('" + mapAttr.MyPK + "')\">隐藏</a></td>";
                    } else {
                        html += "<td style='text-align:right' ><a href=\"javascript:ShowIt('" + mapAttr.MyPK + "')\">显示</a></td>";
                    }
                }

                html += "<td><a href=\"javascript:Up('" + mapAttr.MyPK + "')\">上移</a> - <a href=\"javascript:Down('" + mapAttr.MyPK + "')\">下移</a></td>";
                html += "</tr>";

                $("#Table1 tr:last").after(html);
            }

        });

        function HiddenIt(mypk, i) {
            var mapAttrEn = new Entity("BP.Sys.MapAttr", mypk);
            mapAttrEn.SetPara("SearchVisable", 0);
            mapAttrEn.Update();

            window.location.href = window.location.href;
        }

        function ShowIt(mypk) {
            var mapAttrEn = new Entity("BP.Sys.MapAttr", mypk);
            mapAttrEn.SetPara("SearchVisable", 1);
            mapAttrEn.Update();
            window.location.href = window.location.href;
        }

        function Up(mypk) {
            var mapAttrEn = new Entity("BP.Sys.MapAttr", mypk);
            mapAttrEn.DoMethodReturnString("DoUpTabIdx");
            window.location.href = window.location.href;
        }
        function Down(mypk) {
            var mapAttrEn = new Entity("BP.Sys.MapAttr", mypk);
            mapAttrEn.DoMethodReturnString("DoDownTabIdx");
            window.location.href = window.location.href;
        }

        function Save() {

            var frmID = GetQueryString("FrmID");
            var mapAttrs = new Entities("BP.Sys.MapAttrs");
            mapAttrs.Retrieve("FK_MapData", frmID, "Idx");

            for (var i = 0; i < mapAttrs.length; i++) {

                var mapAttr = mapAttrs[i];
                if (mapAttr.KeyOfEn == 'OID') {
                    continue;
                }

                var mapAttrEn = new Entity("BP.Sys.MapAttr", mapAttr);

                mapAttrEn.Name = $("#TB_" + mapAttrEn.KeyOfEn).val();
                mapAttrEn.UIWidth = $("#TBW_" + mapAttrEn.KeyOfEn).val();
                mapAttrEn.Update();
            }

            window.location.href = window.location.href;
        }

        function SaveAndSetSearchCond() {
            window.location.href = "SearchCond.htm?FrmID=" + GetQueryString("FrmID");
        }
    </script>
</head>
<body>
    <table id="Table1" style="width: 96%;">
        <caption>
            设置显示的列</caption>
        <tr>
            <th>
                #
            </th>
            <th>
                字段
            </th>
            <th>
                中文名
            </th>
            <th>
                宽度
            </th>
            <th>
                类型
            </th>
            <th>
                设置显示/隐藏
            </th>
            <th>
                顺序
            </th>
        </tr>
    </table>
    <input type="button" value="保存" onclick="Save()" />
    <input type="button" value="设置查询条件" onclick="SaveAndSetSearchCond()" />
</body>
</html>
